package com.ce.utils;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.log4j.Logger;

/**
 * @author Administrator
 *
 */
public class EtvNetWork {
	public static Logger log = Logger.getLogger(EtvNetWork.class);
	public static String getTags(String channel) {
		try {
			String strUrl="http://etv.easy3c.net/tags.php";
			HttpClient httpClient = new HttpClient();
			PostMethod postMethod = new PostMethod(strUrl);
			postMethod.addRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
			String repMsg = "";
			postMethod.setParameter("channel", channel);
			int statusCode = httpClient.executeMethod(postMethod);
			log.info("statusCode:"+statusCode);
			if(statusCode != HttpStatus.SC_OK)
				return "";
			repMsg = postMethod.getResponseBodyAsString();
			log.info(repMsg);
			return repMsg;
		} catch (Exception e) {
			log.error(e);
		}
		return "";
	}
	
	public static String getList(String channel, String type, String page) {
		try {
			String strUrl="http://etv.easy3c.net/list.php";
			HttpClient httpClient = new HttpClient();
			PostMethod postMethod = new PostMethod(strUrl);
			postMethod.addRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
			String repMsg = "";
			postMethod.setParameter("channel", channel);
			postMethod.setParameter("type", type);
			postMethod.setParameter("page", page);
			int statusCode = httpClient.executeMethod(postMethod);
			log.info("statusCode:"+statusCode);
			if(statusCode != HttpStatus.SC_OK)
				return "";
			repMsg = postMethod.getResponseBodyAsString();
			log.info(repMsg);
			return repMsg;
		} catch (Exception e) {
			log.error(e);
		}
		return "";
	}
	
	public static String getDetail(String id, String type) {
		try {
			String strUrl="http://etv.easy3c.net/detail.php";
			HttpClient httpClient = new HttpClient();
			PostMethod postMethod = new PostMethod(strUrl);
			postMethod.addRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
			String repMsg = "";
			postMethod.setParameter("id", id);
			postMethod.setParameter("type", type);
			int statusCode = httpClient.executeMethod(postMethod);
			log.info("statusCode:"+statusCode);
			if(statusCode != HttpStatus.SC_OK)
				return "";
			repMsg = postMethod.getResponseBodyAsString();
			log.info(repMsg);
			return repMsg;
		} catch (Exception e) {
			log.error(e);
		}
		return "";
	}
}
